package com.xiyu.service.controller.admin.health;
import com.xiyu.service.vo.health.medicine.MedicineSingleGetOutput;
import com.xiyu.service.vo.health.medicine.MedicineUpdateInput;
import com.xiyu.service.vo.health.medicine.MedicineGetOutput;
import com.xiyu.service.vo.health.medicine.MedicineCreateInput;
import com.xiyu.service.vo.health.medicine.MedicinePageQueryOutput;
import com.xiyu.service.vo.health.medicine.MedicinePageQueryInput;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import jakarta.validation.constraints.*;
import jakarta.validation.*;
import jakarta.servlet.http.*;

import com.xiyu.service.framework.web.web.core.pojo.PageResult;
import com.xiyu.service.framework.web.web.core.pojo.CommonResult;
import static com.xiyu.service.framework.web.web.core.pojo.CommonResult.success;

import com.xiyu.service.framework.excel.core.util.ExcelUtils;

import com.xiyu.service.framework.operateLog.core.annotations.OperateLog;
import static com.xiyu.service.framework.operateLog.core.enums.OperateTypeEnum.*;

import com.xiyu.service.service.health.MedicineService;

@Tag(name = "药品档案")
@RestController
@RequestMapping("/health/medicine")
@Validated
public class MedicineController {

    @Resource
    private MedicineService medicineService;

    @GetMapping("/page-query")
    @Operation(summary = "分页查询药品档案")
    @PreAuthorize("@ss.hasPermission('health:medicine:query')")
    public CommonResult<PageResult<MedicinePageQueryOutput>> pageQuery(@Valid MedicinePageQueryInput inputVO) {
        return success(medicineService.pageQuery(inputVO));
    }

    @PostMapping("/create")
    @Operation(summary = "创建药品档案")
    @PreAuthorize("@ss.hasPermission('health:medicine:create')")
    public CommonResult<Long> create(@Valid @RequestBody MedicineCreateInput inputVO) {
        return success(medicineService.create(inputVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新药品档案")
    @PreAuthorize("@ss.hasPermission('health:medicine:update')")
    public CommonResult<Boolean> update(@Valid @RequestBody MedicineUpdateInput inputVO) {
        return success(medicineService.update(inputVO));
    }

    @DeleteMapping("/deleted")
    @Operation(summary = "删除药品档案")
    @PreAuthorize("@ss.hasPermission('health:medicine:delete')")
    @Parameter(name = "id", description = "药品档案主键ID", example = "")
    public CommonResult<Boolean> deleted(@RequestParam("id") Long id) {
        return success(medicineService.deleted(id));
    }

    @GetMapping("/get")
    @Operation(summary = "获取单个药品档案")
    @Parameter(name = "id", description = "药品档案主键ID", example = "")
    public CommonResult<MedicineGetOutput> get(@RequestParam("id") Long id) {
        return success(medicineService.get(id));
    }

    @GetMapping("/single-get")
    @Operation(summary = "获取单个药品")
    @Parameter(name = "id", description = "药品档案主键ID", example = "")
    public CommonResult<MedicineSingleGetOutput> singleGet(@RequestParam("id") Long id) {
        return success(medicineService.singleGet(id));
    }

}
